<template>
	<div>
		<AplidForm v-bind="formConfig" ref="formEl" v-model="formModel" @submit="onSubmit"  @reset="onReset">
      <div class="fc" v-if="props.operateType == 'audit'">
        <el-button type="primary" @click="onSave(1)">通过</el-button>
        <el-button type="danger" @click="onSave(2)">驳回</el-button>
      </div>
    </AplidForm>
	</div>
</template>

<script setup lang="ts">
import apiMod from '@/apiMod'

const props = defineProps<{
	nowRowData: any
	operateType: string
}>()

const emit = defineEmits(['refresh'])
const formEl = ref(null)
const formModel = ref({
	...props.nowRowData,
})
const formConfig = {
	inline: false,
	labelPosition: 'top',
  showBtn:props.operateType !== 'audit',
	column: [
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: props.nowRowData.dataTypeLabel,
			span: 24,
		},
		{
			label: '',
			tip: '',
      fileType:'application/pdf,image/png,image/jpg,image/jpeg,image/gif,image/webp',
      listType:'picture-card',
			prop: 'material',
			type: 'upload',
      disabled:true,
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
      uploadTip:'请上传图片或PDF格式文件,大小不要超过10MB',
	  rules: [{ required: true, message: '请上传文件或图片' }],
		},
		{
			label: '到期时间',
			prop: 'endTime',
			type: 'date',
			changeField: false,
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 24,
			rules: [{ required: true, message: '请输入姓名' }],
		},
	],
}

const onSave = (reviewStatus)=> {
  formModel.value.reviewStatus = reviewStatus
  formEl.value?.onSubmit()
}

const onReset = ()=> {
  emit('refresh')
}

const onSubmit = (model, done) => {
	if (props.operateType == 'audit') {
		apiMod.view_dpServiceObjectMaterial_approve({
      ...formModel.value
    }).then(() => {
			ElMessage({
				type: 'success',
				message: '操作成功',
			})
			emit('refresh')
			done()
		})
	} else {
		const baseApi = props.nowRowData.id ? 'view_dpServiceObjectMaterial_edit' : 'view_dpServiceObjectMaterial_add'
		apiMod[baseApi]({
			id: props.nowRowData.id,
			material: model.material,
			endTime: model.endTime,
			idCard: model.idCard,
			dataType: model.dataType||'10',
			dataTypeLabel: model.dataTypeLabel||'其他',
			name: model.name||'其他',
			code: 1004,
		}).then(() => {
			ElMessage({
				type: 'success',
				message: '操作成功',
			})
			emit('refresh')
			done()
		})
	}
}
</script>

<style scoped></style>
